trigger SyncToHospital on hospital_approve__c (after update) {
boolean b=false;//标志，判断是否进入代码；
for(hospital_approve__c h:trigger.new){
         if(system.trigger.oldmap.get(h.id).effectivedate__c!=h.effectivedate__c&&h.effectivedate__c!=null
            ||system.trigger.oldmap.get(h.id).approvalstatus__c!=h.approvalstatus__c&&h.approvalstatus__c!=null
            ||system.trigger.oldmap.get(h.id).comments__c!=h.comments__c&&h.comments__c!=null
            ){
               b=true; 
            }
}
if(b){
list<hospital__c> hoslist=new list<hospital__c>();
list<id> hosid=new list<id>();
list<hospital__c> hosupdatel=new list<hospital__c>();
for(hospital_approve__c h:trigger.new){
    hosid.add(h.hospital__c);
}
hoslist=[select id,approvalstatus__c,effectivedate__c,comments__c from hospital__c where id in:hosid];//查询相关医院
for(hospital__c hp:hoslist){
    for(hospital_approve__c ha:trigger.new){
        if(ha.hospital__c==hp.id){
            if(system.trigger.oldmap.get(ha.id).effectivedate__c!=ha.effectivedate__c&&ha.effectivedate__c!=null){//同步生效日期
                hp.effectivedate__c=ha.effectivedate__c;
            }
            if(system.trigger.oldmap.get(ha.id).approvalstatus__c!=ha.approvalstatus__c&&ha.approvalstatus__c!=null){//同步审批状态
                hp.approvalstatus__c=ha.approvalstatus__c;
            }
            if(system.trigger.oldmap.get(ha.id).comments__c!=ha.comments__c&&ha.comments__c!=null){//同步备注
                hp.comments__c=ha.comments__c;
            }
            hosupdatel.add(hp);
        }
    }
}
update hosupdatel;
}





   /*             list<hospital__c> hosupd=new list<hospital__c>();
                hospital__c hp=[select id,approvalstatus__c,effectivedate__c,comments__c from hospital__c where id=:trigger.new[0].hospital__c];
        if(system.trigger.oldmap.get(trigger.new[0].id).effectivedate__c!=trigger.new[0].effectivedate__c&&trigger.new[0].effectivedate__c!=null
            ||system.trigger.oldmap.get(trigger.new[0].id).approvalstatus__c!=trigger.new[0].approvalstatus__c&&trigger.new[0].approvalstatus__c!=null
            ||system.trigger.oldmap.get(trigger.new[0].id).comments__c!=trigger.new[0].comments__c&&trigger.new[0].comments__c!=null
        ){
        if(system.trigger.oldmap.get(trigger.new[0].id).effectivedate__c!=trigger.new[0].effectivedate__c&&trigger.new[0].effectivedate__c!=null){
                if(hp<>null){
                hp.effectivedate__c=trigger.new[0].effectivedate__c;
                
                }
        }
        if(system.trigger.oldmap.get(trigger.new[0].id).approvalstatus__c!=trigger.new[0].approvalstatus__c&&trigger.new[0].approvalstatus__c!=null){
                if(hp<>null){
                hp.approvalstatus__c=trigger.new[0].approvalstatus__c;
                } 
        }
        if(system.trigger.oldmap.get(trigger.new[0].id).comments__c!=trigger.new[0].comments__c&&trigger.new[0].comments__c!=null){
                if(hp<>null){
                hp.comments__c=trigger.new[0].comments__c;
                } 
        }
        update hp;
       }*/
}